var fs = true;
var UserNO = localStorage.getItem("UserName");
mui.plusReady(function() {
	var currentwindow = plus.webview.currentWebview();
	if (currentwindow.TradeOrderNO != '' && currentwindow.TradeOrderNO != undefined) {
		console.log(currentwindow)
		$("#TradeOrderNO").val(currentwindow.TradeOrderNO);
		$("#OutWarehouse").val(currentwindow.OutWarehouse);
		$("#InWarehouse").val(currentwindow.InWarehouse);
		$("#hFromWarehouseID").val(currentwindow.OutWarehouseID);
	} else {
		mui.toast("No parameters brought in。", {
			duration: '1000',
			type: 'div'
		});
	}

	GetMatialInfo();

	plus.nativeUI.closeWaiting();
	//显示当前页面
	//mui.currentWebview.show();
});

function openPositions() {
	mui.openWindow({
		url: 'WmsPurchaseReceiptOrderList_3.html',
		action: UserNO,
		extras: {

		}
	});
}

function openPosition(TradeNO, MaterialNO, LackQty, FromWarehouseID) {
	mui.openWindow({
		url: 'WmsPurchaseReceiptOrderList_3.html',
		action: UserNO,
		extras: {
			TradeOrderNO: TradeNO,
			MaterialNO: MaterialNO,
			LackQty: LackQty,
			FromWarehouseID: FromWarehouseID
		}
	});
}

function GetMatialInfo() {
	document.activeElement.blur();
	var html = '';
	const TradeOrderNO = $("#TradeOrderNO").val();
	const FromWarehouseID = $("#hFromWarehouseID").val();
	if (!TradeOrderNO) {
		mui.toast("No parameters brought in。", {
			duration: '1000',
			type: 'div'
		});
		TradeOrderNO.focus();
		return false;
	}
	xccFormPostAsync("api/PDA/GetTradeInfo_ItemInfo", {
		TradeOrderNO: TradeOrderNO
	}, function(data) {
		if (data.Code === 200) {
			if (data.Items.length != null && data.Items.length > 0) {
				for (var i = 0; i < data.Items.length; i++) {

					html += `
					<li class="mui-table-view-cell">
						 <div class="list-title">MaterialNO:${data.Items[i].MaterialNO}&nbsp;&nbsp;&nbsp;BatchNO:${data.Items[i].BatchNO}</div>
						 <div class="list-detail">StorageNO: ${data.Items[i].StorageNO}</div>
						 <div class="list-detail">RequestQty: ${data.Items[i].RequestQty}</div>
						 <div class="list-detail">ActionQty: ${data.Items[i].ActionQty}</div>
	              </li>
						  `;
				}
				$(".mui-table-view").html(html); // 清空并插入新内容
			} else {
				$(".mui-table-view").html(
					`<li class="mui-table-view-cell" style="color: blue; text-align: center;">Material requisition completed
			</li>`);
			}
		} else {
			mui.toast("Material requisition completed", {
				duration: '1000',
				type: 'div'
			});
			$(".mui-table-view").html(
				`<li class="mui-table-view-cell" style="color: blue; text-align: center;">Material requisition completed
			</li>`);
		}

		plus.nativeUI.closeWaiting();
	}, function(error) {
		$(".mui-table-view").html(
			`<li class="mui-table-view-cell" style="color: blue; text-align: center;">Material requisition completed
		</li>`);
		plus.nativeUI.closeWaiting();
	});

}